#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>


struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;

};


int sumOfLeftLeaves(struct TreeNode* root) {

    if (root == NULL)
        return 0;

    if (root->left != NULL && root->left->right == NULL && root->left->left == NULL)
        return root->left->val + sumOfLeftLeaves(root->right);

    if (root->right != NULL && (root->right->left != NULL || root->right->right != NULL))
        return sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right);

    if (root->left != NULL && (root->left->left != NULL || root->left->right != NULL))
        return sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right);



    return 0;

}
struct TreeNode* Buystruct(int x)
{
    struct TreeNode* newnode = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    if (newnode == NULL)
    {
        perror("malloc fail");
        exit(-1);
    }
    newnode->val = x;
    newnode->left = NULL;
    newnode->right = NULL;

    return newnode;

}

int main()
{
    struct TreeNode tn;
    struct TreeNode* n1 = Buystruct (1);
    struct TreeNode* n2 = Buystruct (2);
    struct TreeNode* n3 = Buystruct (3);
    struct TreeNode* n4 = Buystruct (4);
    struct TreeNode* n5 = Buystruct (5);
    struct TreeNode* n6 = Buystruct (6);
    struct TreeNode* n7 = Buystruct (7);
    n1->left = n2;
    n1->right = n4;
    n2->left = n3;
    n4->left = n5;
    n4->right = n6;
    n3->left = n7;
    int ret=sumOfLeftLeaves(n1);
    printf("%d", ret);
    return 0;
}